package {{folderName}}

import (
	"github.com/gophercloud/gophercloud"
    {{#alloperations}}{{#hasQueryPagin}}"github.com/gophercloud/gophercloud/pagination"{{/hasQueryPagin}}{{/alloperations}}
)
{{#allmodels}}
{{#model}}
{{#isResp}}
{{#isEnum}}
{{#description}}
    // {{{description}}}
{{/description}}

type {{#vendorExtensions.x-classname}}{{vendorExtensions.x-classname}}{{/vendorExtensions.x-classname}}{{^vendorExtensions.x-classname}}{{classname}}{{/vendorExtensions.x-classname}} {{^format}}{{dataType}}{{/format}}{{#format}}{{{format}}}{{/format}}
// List of {{{name}}}
const (
	{{#allowableValues}}
	{{#enumVars}}
	{{^-first}}
	{{/-first}}
	{{name}} {{{classname}}} = "{{{value}}}"
	{{/enumVars}}
	{{/allowableValues}}
){{/isEnum}}{{^isEnum}}{{#description}}
// {{{description}}}{{/description}}
type {{#vendorExtensions.x-classname}}{{vendorExtensions.x-classname}}{{/vendorExtensions.x-classname}}{{^vendorExtensions.x-classname}}{{classname}}{{/vendorExtensions.x-classname}} struct {
{{#vars}}
{{^-first}}
{{/-first}}
{{#description}}
	// {{{description}}}
{{/description}}
	{{name}} {{{datatype}}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"{{#withXml}} xml:"{{baseName}}"{{/withXml}}`
{{/vars}}
}
{{/isEnum}}
{{/isResp}}
{{/model}}
{{/allmodels}}
{{#alloperations}}
{{#operations}}
{{#operation}}
{{#isListContainer}}

type {{{vendorExtensions.x-returnBaseTypeModel}}}s {{{returnType}}}
{{/isListContainer}}
{{#vendorExtensions.isExtractInfo}}
{{#vendorExtensions.x-isPage}}

func Extract{{vendorExtensions.x-nickname}}(r pagination.Page) ({{^isListContainer}}{{{returnType}}}{{/isListContainer}}{{#isListContainer}}{{{vendorExtensions.x-returnBaseTypeModel}}}s{{/isListContainer}}, error) {
	var s {{^isListContainer}}{{{returnType}}}{{/isListContainer}}{{#isListContainer}}{{{vendorExtensions.x-returnBaseTypeModel}}}s{{/isListContainer}}
	err := (r.({{vendorExtensions.x-nickname}}Page)).ExtractInto(&s)
	return s, err
}

type {{vendorExtensions.x-nickname}}Page struct {
	pagination.LinkedPageBase
}

func (r {{vendorExtensions.x-nickname}}Page) IsEmpty() (bool, error) {
	s, err := Extract{{vendorExtensions.x-nickname}}(r)
{{^vendorExtensions.isExtractInfo}}
	return &s == nil, err
{{/vendorExtensions.isExtractInfo}}
{{#vendorExtensions.isExtractInfo}}
	return len(s) == 0, err
{{/vendorExtensions.isExtractInfo}}
}
{{/vendorExtensions.x-isPage}}
{{/vendorExtensions.isExtractInfo}}
{{^vendorExtensions.x-isPage}}

{{#hasReference}}
type {{vendorExtensions.x-nickname}}Result struct {
	gophercloud.Result
}
{{/hasReference}}
{{^hasReference}}
type {{vendorExtensions.x-nickname}}Result struct {
	gophercloud.ErrResult
}
{{/hasReference}}
{{/vendorExtensions.x-isPage}}
{{/operation}}
{{/operations}}
{{/alloperations}}
{{#allmodels}}
{{#model}}
{{#isExtractInfo}}
{{^isQueryResponse}}

func (r {{vendorExtensions.x-nickname}}Result) Extract() (*{{vendorExtensions.x-classname}}, error) {
	var s *{{vendorExtensions.x-classname}}
	err := r.ExtractInto(&s)
	return s, err
}
{{/isQueryResponse}}
{{#isQueryResponse}}

func (page {{vendorExtensions.x-classname}}Page) NextPageURL() (string, error) {
	var s struct {
		Links []gophercloud.Link `json:"{{vendorExtensions.x-classnameLowerCase}}_links"`
	}
	err := page.ExtractInto(&s)
	if err != nil {
		return "", err
	}
	return gophercloud.ExtractNextURL(s.Links)
}

func Extract{{vendorExtensions.x-classname}}(r pagination.Page) ({{vendorExtensions.x-classname}}, error) {
	var s {{vendorExtensions.x-classname}}
{{#vars}}
	{{#isContainer}}s.{{name}} = make({{{datatype}}}, 0){{/isContainer}}
{{/vars}}
	err := (r.({{vendorExtensions.x-classname}}Page)).ExtractInto(&s)
	return s, err
}

type {{vendorExtensions.x-classname}}Page struct {
	pagination.LinkedPageBase
}

func (r {{vendorExtensions.x-classname}}Page) IsEmpty() (bool, error) {
	s, err := Extract{{vendorExtensions.x-classname}}(r)
{{#isExtractInfo}}
	return &s == nil, err
{{/isExtractInfo}}
{{^isExtractInfo}}
	return len(s) == 0, err
{{/isExtractInfo}}
}
{{/isQueryResponse}}
 {{/isExtractInfo}}
 {{/model}}
 {{/allmodels}}
 {{#alloperations}}
 {{#operations}}
 {{#operation}}
 {{#vendorExtensions.isExtractInfo}}
 {{^vendorExtensions.x-isPage}}

 func (r {{vendorExtensions.x-nickname}}Result) Extract() (*{{vendorExtensions.x-returnBaseTypeModel}}s, error) {
 	var s *{{vendorExtensions.x-returnBaseTypeModel}}s
 	err := r.ExtractInto(&s)
 	return s, err
 }
{{/vendorExtensions.x-isPage}}
{{/vendorExtensions.isExtractInfo}}
{{/operation}}
{{/operations}}
{{/alloperations}}